package cc.wsyw126.java.nowcoder.ali;

import java.util.Scanner;

/**
 * Created by Administrator on 2017/4/26.
 */
public class Main {

    public boolean match(char[] str, char[] pattern) {
        if (str == null || pattern == null) {
            return false;
        }
        if (str.length ==0)return false;
        int strIndex = 0;
        int patternIndex = 0;
        return matchCore(str, strIndex, pattern, patternIndex);
    }

    public boolean matchCore(char[] str, int strIndex, char[] pattern, int patternIndex) {
        if (strIndex == str.length && patternIndex == pattern.length) {
            return true;
        }
        if (strIndex != str.length && patternIndex == pattern.length) {
            return false;
        }
        if (strIndex == str.length && patternIndex != pattern.length) {
            if (patternIndex + 1 < pattern.length && pattern[patternIndex + 1] == '*') {
                return matchCore(str, strIndex, pattern, patternIndex + 2);
            }
            return false;
        }
        if (patternIndex + 1 < pattern.length && pattern[patternIndex + 1] == '*') {
            if (pattern[patternIndex] == str[strIndex] || (pattern[patternIndex] == '?' && strIndex != str.length)) {
                return matchCore(str, strIndex, pattern, patternIndex + 2)
                        || matchCore(str, strIndex + 1, pattern, patternIndex + 2)
                        || matchCore(str, strIndex + 1, pattern, patternIndex);
            } else {
                return matchCore(str, strIndex, pattern, patternIndex + 2);
            }
        }
        if (pattern[patternIndex] == str[strIndex] || (pattern[patternIndex] == '?' && strIndex != str.length)) {
            return matchCore(str, strIndex + 1, pattern, patternIndex + 1);
        }
        return false;
    }


    public static void main(String[] args) {
        Main main = new Main();
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String source = scanner.nextLine();
            String pattern = scanner.nextLine();
            char[] sourceChars = source.toCharArray();
            StringBuffer stringBuffer = new StringBuffer();
            for (int i = 0; i < pattern.length(); i++) {
                if (pattern.charAt(i) == '*') {
                    stringBuffer.append("?*");
                } else {
                    stringBuffer.append(pattern.charAt(i));
                }
            }
            char[] patternChars = stringBuffer.toString().toCharArray();
            boolean match = main.match(sourceChars, patternChars);
            int filter = match ? 1 : 0;
            System.out.println(filter);
        }
    }
}
